package com.zff.rental.controller;


import com.zff.rental.common.Result;
import com.zff.rental.entity.apartment.RoomEntity;
import com.zff.rental.repository.apartment.RoomRepository;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;


/**
 * 测试
 *
 * @author HCY
 */
@Log4j2
@RestController
@RequestMapping("/test")
public class TestController {
    /**
     * 房间
     */
    @Resource
    protected RoomRepository roomRepository;

    /**
     * 房间详情
     */
    @GetMapping("/roomDetails")
    @Transactional
    public Result<Object> details(@RequestParam("id") Long id) {
        log.info("测试1");
        RoomEntity byId = roomRepository.findById(id).get();
        byId.setMemo(LocalDateTime.now().toString());
        log.info("测试2");
        RoomEntity save = roomRepository.save(byId);
        log.info("测试3");
        return Result.success(save);
    }

    /**
     * 获取版本
     */
    @GetMapping("/getVersion")
    public Result<String> getVersion() {
        return Result.success("1.0.0");
    }
}